package com.yw.pms.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yw.pms.service.OperatorService;
import com.yw.pms.utils.CommonResp;

@Controller
public class LoginController {
	
	@Resource
	private OperatorService operatorService;
	
	@RequestMapping("/")
	public String index(){
		return "index2";
	}
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody CommonResp<String> login(HttpSession session,String loginName,String password){
		return operatorService.checkLogin(session,loginName,password);
	}
	
	@RequestMapping(value="/home")
	String home(HttpSession session,Model model){
		if(session.getAttribute("operator") == null){
			return "errorpage/error";
		}
		return "product";
	}
	
	@RequestMapping(value="/logout")
	String logout(HttpSession session){
		session.invalidate();
		return "redirect:/";
	}
}
